def isPrime(n):
  for i in range(2, int(n**0.5)+1):
     if n%i==0:
          return False
  return True

n=int(input())
if n<1000 or n>10000:
    n=0
    print(n)
else:
 n1=n//1000
 n2=(n//100)%10
 n3=(n//10)%10
 n4=n%10
 mp=0

 if isPrime(n1) and mp<n1: mp=n1
 if isPrime(n2) and mp<n2: mp=n2
 if isPrime(n3) and mp<n3: mp=n3
 if isPrime(n4) and mp<n4: mp=n4
 n12=n1*10+n2
 if isPrime(n12) and mp<n12: mp=n12
 n13=n1*10+n3
 if isPrime(n13) and mp<n13: mp=n13
 n14=n1*10+n4
 if isPrime(n14) and mp<n14: mp=n14
 n23=n2*10+n3
 if isPrime(n23) and mp<n23: mp=n23
 n24=n2*10+n4
 if isPrime(n24) and mp<n24: mp=n24
 n34=n3*10+n4
 if isPrime(n34) and mp<n34: mp=n34
 n123=n1*100+n2*10+n3
 if isPrime(n123) and mp<n123: mp=n123
 n124=n1*100+n2*10+n4
 if isPrime(n124) and mp<n124: mp=n124
 n134=n1*100+n3*10+n4
 if isPrime(n134) and mp<n134: mp=n134
 n234=n2*100+n3*10+n4
 if isPrime(n234) and mp<n234: mp=n234
 if isPrime(n) and mp<n: mp=n
 print(mp)
